package cn.iocoder.yudao.module.eval;

import cn.iocoder.yudao.module.eval.controller.admin.major.vo.MajorImportExcelVO;
import cn.idev.excel.context.AnalysisContext;
import cn.idev.excel.event.AnalysisEventListener;
import cn.idev.excel.metadata.Head;

import java.util.ArrayList;
import java.util.List;

public class HeaderAnalysisListener extends AnalysisEventListener<MajorImportExcelVO> {
    
    private List<String> actualHeaders = new ArrayList<>();
    private List<String> expectedHeaders = new ArrayList<>();
    private List<Boolean> matchResults = new ArrayList<>();
    
    public HeaderAnalysisListener() {
        // 初始化期望的表头
        expectedHeaders.add("大类编码");
        expectedHeaders.add("专业编码");
        expectedHeaders.add("等级");
        expectedHeaders.add("专业名称");
        expectedHeaders.add("培养目标");
        expectedHeaders.add("学习年限");
        expectedHeaders.add("职业能力");
        expectedHeaders.add("对应或相关职业（工种）");
        expectedHeaders.add("职业资格(职业技能等级)");
        expectedHeaders.add("教学内容与要求");
        expectedHeaders.add("对应上一级专业编码");
        expectedHeaders.add("对应下一级专业编码");
    }
    
    @Override
    public void invokeHeadMap(java.util.Map<Integer, String> headMap, AnalysisContext context) {
        System.out.println("表头Map: " + headMap);
        // 收集实际表头
        for (int i = 0; i < headMap.size(); i++) {
            actualHeaders.add(headMap.get(i));
        }
        super.invokeHeadMap(headMap, context);
    }
    
    @Override
    public void invoke(MajorImportExcelVO data, AnalysisContext context) {
        // 不处理数据，只分析表头
        System.out.println("数据行: " + data);
    }
    
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        System.out.println("所有分析完成");
        // 比较表头
        compareHeaders();
    }
    
    private void compareHeaders() {
        for (int i = 0; i < Math.min(actualHeaders.size(), expectedHeaders.size()); i++) {
            String actual = actualHeaders.get(i);
            String expected = expectedHeaders.get(i);
            matchResults.add(expected.equals(actual));
        }
    }
    
    public List<String> getActualHeaders() {
        return actualHeaders;
    }
    
    public List<String> getExpectedHeaders() {
        return expectedHeaders;
    }
    
    public List<Boolean> getHeaderMatchResult() {
        return matchResults;
    }
}